'''
Author: '遂季琉璃' 1846621493@qq.com
Date: 2025-07-29 22:46:35
LastEditors: '遂季琉璃' 1846621493@qq.com
LastEditTime: 2025-10-12 20:38:05
FilePath: \jqktrader-main\测试远端服务.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
# In[1]
import requests

# 服务地址
BASE_URL = "http://jijie.site:6030"

def test_balance():
    """测试获取资金信息接口"""
    resp = requests.get(f"{BASE_URL}/balance")
    print("资金信息：", resp.json())

def test_position():
    """测试获取持仓信息接口"""
    resp = requests.get(f"{BASE_URL}/position")
    print("持仓信息：", resp.json())

def test_today_entrusts():
    """测试获取当日委托接口"""
    resp = requests.get(f"{BASE_URL}/today_entrusts")
    print("当日委托：", resp.json())

def test_today_trades():
    """测试获取当日成交接口"""
    resp = requests.get(f"{BASE_URL}/today_trades")
    print("当日成交：", resp.json())

def test_cancel_entrusts():
    """测试获取可撤单列表接口"""
    resp = requests.get(f"{BASE_URL}/cancel_entrusts")
    print("可撤单列表：", resp.json())

def test_buy():
    """测试买入接口"""
    data = {
        "code": "600010",  # 示例股票代码
        "price": "2.70",  # 示例价格
        "amount": "100"    # 示例数量
    }
    resp = requests.post(f"{BASE_URL}/buy", data=data)
    print("买入结果：", resp.json())

def test_sell():
    """测试卖出接口"""
    data = {
        "code": "601238",
        "price": "7.72",
        "amount": "100"
    }
    resp = requests.post(f"{BASE_URL}/sell", data=data)
    print("卖出结果：", resp.json())

def test_market_buy():
    """测试市价买入接口"""
    data = {
        "code": "600010",
        "amount": "100"
    }
    resp = requests.post(f"{BASE_URL}/market_buy", data=data)
    print("市价买入结果：", resp.json())

def test_market_sell():
    """测试市价卖出接口"""
    data = {
        "code": "600010",
        "amount": "100"
    }
    resp = requests.post(f"{BASE_URL}/market_sell", data=data)
    print("市价卖出结果：", resp.json())

def test_cancel():
    """测试撤单接口"""
    data = {
        "entrust_no": "0262640144"  # 这里需要替换为实际可撤单编号
    }
    resp = requests.post(f"{BASE_URL}/cancel", data=data)
    print("撤单结果：", resp.json())

def test_cancel_all():
    """测试批量撤单接口"""
    resp = requests.post(f"{BASE_URL}/cancel_all")
    print("批量撤单结果：", resp.json())

def test_refresh():
    """测试刷新接口"""
    resp = requests.post(f"{BASE_URL}/refresh")
    print("刷新结果：", resp.json())

def test_exit():
    """测试退出客户端接口"""
    resp = requests.post(f"{BASE_URL}/exit")
    print("退出结果：", resp.json())

if __name__ == "__main__":
    # 依次调用所有测试函数
    # 获取资金状况
    # test_balance()
    # 获取当前持仓
    test_position()
    test_today_entrusts()
    # test_today_trades()
    # test_cancel_entrusts()
    # test_buy()
    # test_sell()
    # test_market_buy()
    # test_market_sell()
    # test_cancel()
    # test_cancel_all() # 全撤
    # test_refresh()
    # test_exit()
# In[2]


# In[3]